import * as THREE from "three";
// 引入threejs 的扩展库  相机控件
import { OrbitControls } from "three/addons/controls/OrbitControls.js";
const OrbitControls_fun = function (className) {


    // ******************创建一个场景*************

    const scene = new THREE.Scene();
    const geometry = new THREE.BoxGeometry(80, 80, 80);
    const material = new THREE.MeshLambertMaterial({
        color: 0x00ffa0,
        transparent: false,
        opacity: 1,
    });
    const cube = new THREE.Mesh(geometry, material);
    cube.position.set(0, 0, 0);
    scene.add(cube);
    // 创建坐标
    const xyz = new THREE.AxesHelper(100);
    scene.add(xyz);
    // ****************添加光源*********************
    const light = new THREE.PointLight(0xffffff, 1);
    light.intensity = 20.0;
    light.decay = 0.0;
    light.position.set(1400, 500, 200);
    scene.add(light);
    console.log(light, "光源");

    // *****************照相机******************
    const width = 800;
    const height = 500;
    //   画布大小设置全屏
    //   const width = window.innerWidth;
    //   const height = window.innerHeight;
    const camera = new THREE.PerspectiveCamera(30, width / height, 0.1, 3000);
    camera.position.set(200, 200, 200);
    camera.lookAt(cube.position);

    // *****************渲染器*****canvas*************
    const renderer = new THREE.WebGLRenderer();
    renderer.setSize(width, height);
    renderer.render(scene, camera);
    const Dom = document.querySelector(className);
    console.log(Dom, "dom");
    Dom.appendChild(renderer.domElement);

    //******************创建一个相机控件***************
    // 创建一个相机控件
    const cintrols = new OrbitControls(camera, renderer.domElement);
    // 监听相机控件的操作:鼠标、键盘事件
    cintrols.addEventListener("change", function () {
        // console.log("相机的位置：",camera.position );
        renderer.render(scene, camera);
    });
}
export {OrbitControls_fun} 